CXX=gcc
CXXFLAGS=-march=sapphirerapids -O3 -g -c
AS=gcc
ASFLAGS=-march=sapphirerapids -c
BENCH=benchamx.bin
PEAK=peak.bin
OBJS_BENCH=benchamx.o libamx.o libavx.o utils.o argtable3.o
OBJS_PEAK=amx_peak.o argtable3.o

.PHONY:all clean run testbuild

all : ${BENCH} ${PEAK}

${BENCH} : ${OBJS_BENCH}
	${CXX} -o $@ $^

ubench.bin : ubench.o argtable3.o
	${CXX} -fopenmp -o $@ $^

${PEAK} : ${OBJS_PEAK}
	${CXX} -fopenmp -o $@ $^

benchamx.o : benchamx.c libamx.h
	${CXX} ${CXXFLAGS} -o $@ $<

utils.o : utils.c utils.h
	${CXX} ${CXXFLAGS} -o $@ $<

libamx.o : libamx.s libamx.h
	${AS} ${ASFLAGS} -o $@ $<

libavx.o : libavx.s libavx.h
	${AS} ${ASFLAGS} -o $@ $<

argtable3.o : argtable3.c argtable3.h
	${CXX} ${CXXFLAGS} -o $@ $<

amx_peak.o : amx_peak.c
	${CXX} ${CXXFLAGS} -fopenmp -o $@ $<

ubench.o : ubench.c
	${CXX} ${CXXFLAGS} -fopenmp -o $@ $<

run_sim:
	@sde64 -spr -- ./${BENCH}

run_bind:
	@taskset -c 2 ./${BENCH}

run_bind_smt:
	@taskset -c 2 ./${BENCH} -m

run_peak:
	@taskset -c 2 ./peak.bin

testbuild:
	${CXX} ${CXXFLAGS} -o amx_selftest.bin amx_selftest.c

clean:
	@rm -f ${BENCH} ${OBJS_BENCH} ${PEAK} ${OBJS_PEAK} amx_selftest.bin
